package cn.yuan.xiaoyu.testmodule.activity;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import butterknife.OnClick;
import cn.yuan.xiaoyu.R;
import cn.yuan.xiaoyu.commonmodule.activity.BaseActivity;
import cn.yuan.xiaoyu.testmodule.utils.PermissionsUtils;

/**
 * Created by yukuoyuan on 2017/3/31.
 */

public class RecycleviewsActivity extends BaseActivity implements PermissionsUtils.OnPermissionListener {

    @Override
    protected void bindPresenter() {

    }

    @Override
    protected void initData(Bundle extras) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_recycleviews;
    }

    @Override
    protected void initToolbar() {
    }


    @OnClick({R.id.iv_toolbar_left, R.id.tv_toolbar_title, R.id.bt_test_01, R.id.bt_test_02})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_toolbar_left:
                onBackPressed();
                break;
            case R.id.tv_toolbar_title:
                break;
            case R.id.bt_test_01:
                PermissionsUtils.instance().requestPermission(this, Manifest.permission.CALL_PHONE, 111, this);
                break;
            case R.id.bt_test_02:
                break;
        }
    }

    /**
     * 权限申请的回调
     *
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        PermissionsUtils.instance().onRequestPermissionsResult(requestCode, grantResults, this);
    }

    /**
     * 拨打电话
     */
    public void callPhone() {
        Intent intent = new Intent(Intent.ACTION_CALL);
        Uri data = Uri.parse("tel:" + "13");
        intent.setData(data);
        startActivity(intent);
    }

    @Override
    public void onRequestPermissionSuccess(int requestCode) {
        showToast(this, "授权成功");
        callPhone();
    }

    @Override
    public void onRequestPermissionFailure(int requestCode) {
        showToast(this, "授权失败");

    }
}
